package com.moleq.dialog;

import java.util.List;

import android.content.Context;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.Button;
import android.widget.GridView;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.ListAdapter;

import com.moleq.adapter.FuncSelectionAdapter;
import com.moleq.base.MoleQBaseDialog;
import com.moleq.device.DeviceManager;
import com.moleq.logic.MoleQConstants;
import com.moleq.logic.TransactionManager;
import com.moleq.mgpos.widget.DisplayScreen;
import com.moleq.mgpos.widget.NumberPadForPayment;
import com.moleq.models.FreeFunction;
import com.moleq.models.FunctionPanel;
import com.moleq.mgpos.activities.R;
import com.moleq.service.ServiceManager;
import com.moleq.util.MoleQUtil;

public class FuncSelectionDialog2 extends MoleQBaseDialog {

	
	private ImageButton btnBack;

	private GridView dataGird;
	private FuncSelectionAdapter mAdapter;
	private List<FunctionPanel> mData;

	
	public FuncSelectionDialog2(Context context) {
		super(context, R.style.dialog, context);
		mContext = context;
		constructor();
		// TODO Auto-generated constructor stub
	}

	public FuncSelectionDialog2(Context context, int theme) {
		super(context, theme);
		mContext = context;
		constructor();
		// TODO Auto-generated constructor stub
	}
	
	public void constructor(){
		
	}
	
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);

		this.setContentView(R.layout.dialog_function_selection_dynamic);
		this.setCancelable(false);
		
		dataGird = (GridView)findViewById(R.id.gvFunctionSelection);
		
		btnBack = (ImageButton) findViewById(R.id.ibFuncSelectionClose);
		btnBack.setOnClickListener(mOnClickListener);
	
	}
	
	public void show(){
		super.show();
		
		mData = ServiceManager.getInstance().mFunctionPanelService.getAllFunctionPanel();
		
		mAdapter = new FuncSelectionAdapter(mContext, mData);
		mAdapter.setOnItemClicklistener(mOnClickListener);
		dataGird.setAdapter(mAdapter);
//		dataGird.setOnItemClickListener(mItemClickListener );
	}

	

	private Button.OnClickListener mOnClickListener = new Button.OnClickListener() {

		@Override
		public void onClick(View v) {
			
			if(v.getId() == R.id.ibFuncSelectionClose){
				dismiss();
			}else{
				
				FunctionPanel fp = (FunctionPanel) v.getTag();
				if(fp != null){
//					onCloseWithReturn(fp.getTp_func_key(), "");
					
					onReturnValue(MoleQConstants.ACTIVE_FUNCTION, fp);
					dismiss();
				}
			}
			

		}

	};

}
